/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014-7-16         luwei
 */

package com.tianci.appstore.ui.widget;

import android.graphics.Canvas;
import android.graphics.drawable.AnimationDrawable;

public class CustomAnimationDrawable extends AnimationDrawable {

    private int mNumber = 0;

    public interface AnimationDrawableListener {
        public void onAnimationEnd();
    }

    private AnimationDrawableListener mAnimListener = null;

    public void setAnimationDrawableListener(AnimationDrawableListener listener) {
        this.mAnimListener = listener;
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        mNumber++;
        if (mNumber >= getNumberOfFrames() - 1) {
            if (mAnimListener != null) {
                mAnimListener.onAnimationEnd();
            }
        }
    }

    @Override
    public void start() {
        mNumber = 0;
        super.start();
    }

}
